package com.nt.oam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.nt.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.nt.common.annotation.Log;
import com.nt.common.core.controller.BaseController;
import com.nt.common.core.domain.AjaxResult;
import com.nt.common.enums.BusinessType;
import com.nt.oam.domain.AntHospitalOamRecord;
import com.nt.oam.service.IAntHospitalOamRecordService;
import com.nt.common.utils.poi.ExcelUtil;
import com.nt.common.core.page.TableDataInfo;

/**
 * 运维记录Controller
 *
 * @author JZFeng
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/oam/record")
public class AntHospitalOamRecordController extends BaseController {
    @Autowired
    private IAntHospitalOamRecordService antHospitalOamRecordService;

    /**
     * 查询运维记录列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AntHospitalOamRecord antHospitalOamRecord) {
        startPage();
        List<AntHospitalOamRecord> list = antHospitalOamRecordService.selectAntHospitalOamRecordList(antHospitalOamRecord);
        return getDataTable(list);
    }

    /**
     * 导出运维记录列表
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:export')")
    @Log(title = "运维记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AntHospitalOamRecord antHospitalOamRecord) {
        List<AntHospitalOamRecord> list = antHospitalOamRecordService.selectAntHospitalOamRecordList(antHospitalOamRecord);
        ExcelUtil<AntHospitalOamRecord> util = new ExcelUtil<AntHospitalOamRecord>(AntHospitalOamRecord.class);
        util.exportExcel(response, list, "运维记录数据");
    }

    /**
     * 获取运维记录详细信息
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:query')")
    @GetMapping(value = "/{oamRecordId}")
    public AjaxResult getInfo(@PathVariable("oamRecordId") Long oamRecordId) {
        return success(antHospitalOamRecordService.selectAntHospitalOamRecordByOamRecordId(oamRecordId));
    }

    /**
     * 新增运维记录
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:add')")
    @Log(title = "运维记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AntHospitalOamRecord antHospitalOamRecord) {
        return toAjax(antHospitalOamRecordService.insertAntHospitalOamRecord(antHospitalOamRecord));
    }

    /**
     * 修改运维记录
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:edit')")
    @Log(title = "运维记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AntHospitalOamRecord antHospitalOamRecord) {
        return toAjax(antHospitalOamRecordService.updateAntHospitalOamRecord(antHospitalOamRecord));
    }

    /**
     * 删除运维记录
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:remove')")
    @Log(title = "运维记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{oamRecordIds}")
    public AjaxResult remove(@PathVariable Long[] oamRecordIds) {
        return toAjax(antHospitalOamRecordService.deleteAntHospitalOamRecordByOamRecordIds(oamRecordIds));
    }

    /**
     * 运维记录详情页
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:query')")
    @GetMapping(value = "/details/{oamRecordId}")
    public AjaxResult getOamRecordDetails(@PathVariable("oamRecordId") Long oamRecordId) {
        return success(antHospitalOamRecordService.selectOamRecordDeatilVo(oamRecordId));
    }

    /**
     * 运维记录其他信息（资产信息，服务器信息）
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:query')")
    @GetMapping(value = "/other/message")
    public AjaxResult getOamRecordOtherMessage(@RequestParam Long projectId) {
        return success(antHospitalOamRecordService.selectOamOtherMessage(projectId));
    }
    /**
     * 医院对应其他信息（项目信息，资产信息，服务器信息）
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:query')")
    @GetMapping(value = "/all/message")
    public AjaxResult getAllMessage(@RequestParam Long hospitalId) {
        return success(antHospitalOamRecordService.selectAllMessage(hospitalId));
    }



    /**
     * 获取页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:query')")
    @GetMapping(value = "/get/isModify")
    public AjaxResult getRecordModify(@RequestParam Long recordId) {
        return success(antHospitalOamRecordService.selectRecordModify(recordId));
    }

    /**
     * 修改页面是否在修改的状态
     */
    @Anonymous
    @PreAuthorize("@ss.hasPermi('oam:record:edit')")
    @Log(title = "运维记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit/modify/{recordId}")
    public AjaxResult editModify(@PathVariable("recordId") Long recordId) {
        int isModify = 1;
        return toAjax(antHospitalOamRecordService.updateRecordModify(recordId,isModify));
    }

}
